import { set } from 'nprogress';
import { defineStore } from 'pinia';
const flowNodesStore = defineStore(
    'flowNodes',
    {
        state: () => ({
            flowNodes: [],// 初始化空数组,
            standard_list: [], //组件标准列表
            template_list: [], //模板列表
        }),
        actions: {
            // 获取 flowNodes
            getFlowNodes() {
                return this.flowNodes;
            },
            getFlowNodesById(_id) {
                return this.flowNodes.find(node => node.id === _id);
            },
            // 设置 flowNodes
            setFlowNodes(nodes, flag = 0) {
                this.flowNodes = nodes;
            },
            setFlowNodesById(_id, node) {
                const index = this.flowNodes.findIndex(node => node.id === _id);
                if (index !== -1) {
                    this.flowNodes[index] = node;
                }
            },
            addFlowNode(node) {
                this.flowNodes.push(node);
            },
            addFlowNodes(node) {
                this.flowNodes.push(node);
            },
            deleteFlowNodesById(_id) {
                const index = this.flowNodes.findIndex(node => node.id === _id);
                if (index !== -1) {
                    this.flowNodes.splice(index, 1);
                }
            },
            setStandardList(standard_list) {
                this.standard_list = standard_list;
            },
            getStandardList() {
                return this.standard_list;
            },
            setTemplateList(template_list) {
                this.template_list = template_list;
            },
            getTemplateList() {
                return this.template_list;
            }
        }
    }
);

export default flowNodesStore;